//*****************************************************************
// ControlThread.h
//
//  Created on: Jan 21, 2012
//      Author: Christopher Wood
//              Robert Livosi
//
//  $Id: ControlThread.h 24 2012-01-28 02:54:38Z caw4567@gmail.com $
//*****************************************************************

#ifndef CONTROLTHREAD_H_
#define CONTROLTHREAD_H_

#include "Project2.h"
#include "TransformThread.h"

// Resolve cyclic dependency
class TransformThread;
class IOThreadGroup;

/**
 * This is an abstract class that is responsible for providing an
 * interface to other control threads (user input) for specific
 * transformation function implementations. Subclasses of this type
 * are responsible for controlling the execution of the analog
 * I/O threads and the corresponding transform thread.
 */
class ControlThread
{
public:
	/**
	 * Default constructor that sets the transform and I/O threads.
	 *
	 * @param tThread - the desired transform thread to control.
	 * @param ioGroup - the I/O group that is managed.
	 */
	ControlThread(TransformThread* tThread, IOThreadGroup* ioGroup);

	/**
	 * Default destructor.
	 */
	virtual ~ControlThread();

	/**
	 * Retrieve the transform object being controlled by this thread.
	 *
	 * @return a pointer to the transform thread object
	 */
	TransformThread* getTransformer();

	/**
	 * Retrieve a pointer to the IOThreadGroup object being controlled by this thread.
	 *
	 * @param a pointer to the IOThreadGroup object.
	 */
	IOThreadGroup* getIOThreadGroup();

	/**
	 * Determine if this thread is done controlling the others.
	 *
	 * @return true if done, false otherwise.
	 */
	bool isComplete();

	/**
	 * Set the control completion status.
	 *
	 * @param b - new boolean value.
	 */
	void setComplete(bool b);

	/**
	 * Start the thread.
	 */
	virtual void run() = 0;

protected:
	// Pointer to the transform object this thread controls.
	TransformThread* transformer;

	// Pointer to the input/output thread group this thread controls.
	IOThreadGroup* ioGroup;

	// Boolean flag indicating the status of the thread.
	volatile bool threadAlive;

	// Boolean flag indicating thread control complete.
	volatile bool controlComplete;

	// The user input thread ID
	pthread_t threadID;
};

#endif /* CONTROLTHREAD_H_ */
